public class num877 {
    public boolean stoneGame(int[] piles) {
        int len = piles.length;
        int[][] arr = new int[len][len];
        for (int i = 0; i < len; i++) {
            arr[i][i] = piles[i];
        }
        for (int i = len - 2; i >= 0; i--) {
            for (int j = i + 1; j < len; j++) {
                arr[i][j] = Math.max(piles[i] - arr[i + 1][j],piles[j] - arr[i][j - 1]);
            }
        }
        return arr[0][len - 1] > 0;
    }
}
